// ApiCallback.java
package com.example.reward.api;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public abstract class ApiCallback<T> implements Callback<T> {

    @Override
    public void onResponse(Call<T> call, Response<T> response) {
         if (response.isSuccessful() && response.body() != null) {
            onSuccess(response.body());
        } else {
            onError("请求失败，状态码：" + response.code());
        }
    }

    @Override
    public void onFailure(Call<T> call, Throwable t) {
        onError("请求失败：" + t.getMessage());
    }

    // 由调用方实现
    public abstract void onSuccess(T result);

    public abstract void onError(String errorMsg);
}
